<?php

namespace app\api\controller;

use app\api\model\Category as CategoryModel;
use app\api\model\Lesson as LessonModel;

/**
 * 课程
 * Class Lesson
 * @package app\api\controller
 */
class Lesson extends Controller
{
    /**
     * 课程列表
     * @return array
     * @throws \think\exception\DbException
     */
    public function lists()
    {
        $user = $this->getUser();
        $model = new CategoryModel;
        $list = $model->getList($this->request->post());
        return $this->renderSuccess(compact('list'));
    }

    /**
     * 课程的所有章
     * @param $cata_id
     * @return array
     * @throws \think\exception\DbException
     */
    public function chapter()
    {
        $user = $this->getUser();
        $model = new CategoryModel;
        $list = $model->getChapter($this->request->post());
        return $this->renderSuccess(compact('list'));
    }

    /**
     * 课程章的所有节
     * @param $cata_id
     * @return array
     * @throws \think\exception\DbException
     */
    public function node()
    {
        $user = $this->getUser();
        $model = new CategoryModel;
        $list = $model->getList($this->request->post());
        return $this->renderSuccess(compact('list'));
    }

    /**
     * 获取节所有内容
     */
    public function content(){
        //$user = $this->getUser();
        $model = new LessonModel();
        $content = $model->content($this->request->post());

        if ($content){
            return $this->renderSuccess(compact('content'));
        }else{
            return $this->renderError($model->getError());
        }
    }
}